package com.dm.utils;

import com.dm.constants.Constants;
import com.dm.pojo.DmUser;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @Author DongJunJun
 * @Date 2022/9/8 23:56
 */
public class TokenUtil {
    public static String generateToken(DmUser user) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(Constants.TOKEN_PREFIX);
        stringBuffer.append("PC-");
        stringBuffer.append(CommonsCode.md5Hex(user.getPhone()+"-",null));
        stringBuffer.append(user.getId() + "-");
        stringBuffer.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "-");
        stringBuffer.append(UUID.randomUUID().toString().substring(0, 6));
        return stringBuffer.toString();
    }
}
